import * as events from './events'
import axios from 'axios'

export const testAction = (context) => {
  context.commit(events.TEST_EVENT, 'test')
}

export const getUserInfo = (context) => {
  return new Promise((resolve, reject) => {
    axios.get('/memberBusniess/query/busniessInfo?num=' + Math.random()).then((data) => {
      resolve(data)
      if (data.data.httpCode === 200) {
        context.commit(events.CHANGE_USER_INFO, data.data.data)
      } else {}
    }).catch((err) => {
      console.log(err)
      reject(err)
    })
  })
}

export const getLoginOut = (context) => {
  return new Promise((resolve) => {
    axios.post('/member/logout').then((data) => {
      resolve(data)
      if (data.data.httpCode === 200) {
        context.commit(events.USER_LOGIN_OUT, data.data.data)
      } else {

      }
    }).catch((err) => {
      console.log(err)
    })
  })
}
